package com.netty.test.service;

import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

public class BackendHandler extends ChannelInboundHandlerAdapter {
    private final Channel inboundChannel;

    public BackendHandler(Channel inboundChannel) {
        this.inboundChannel = inboundChannel;
    }

    @Override
    public void channelRead(final ChannelHandlerContext ctx, Object msg) {
        if ( inboundChannel.isActive() ) {
            inboundChannel.writeAndFlush(msg);
        } else {
            ctx.close();
        }
    }

}
